package com.she.iiicoursecenter.adapter;

import java.util.ArrayList;
import java.util.List;

import ken.app.helper.Helper;

import com.she.iiicoursecenter.R;
import com.she.iiicoursecenter.iiiApplication;
import com.she.iiicoursecenter.event.connect.bean.GetMsgBean;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class Tab4_Adapter extends GeneralAdapter {

	static ArrayList<GetMsgBean> mDataList;
	static Handler mhandler;
	static GenSelectAllListItemView mGenSelectAllView = new GenSelectAllListItemView();

	public Tab4_Adapter(Context context, List<?> dataList) {
		super(context, mGenSelectAllView);
		mDataList = (ArrayList<GetMsgBean>) dataList;
		// mhandler = handler;
		this.setData(mDataList);
	}

	public static class GenSelectAllListItemView extends GenView {
		LayoutInflater inflater;

		@Override
		protected View genBody(Context context, View convertView, final Object element, final int position) {

			if (inflater == null) {
				inflater = LayoutInflater.from(context);
			}
			final ViewHolder holder;
			if (convertView != null && convertView.getTag() instanceof ViewHolder) {
				holder = (ViewHolder) convertView.getTag();
			} else {
				convertView = inflater.inflate(R.layout.tab4_raw, null);
				holder = new ViewHolder();
				holder.title = (TextView) convertView.findViewById(R.id.tab4_raw_title);
				holder.date = (TextView) convertView.findViewById(R.id.tab4_raw_date);
				holder.img = (ImageView) convertView.findViewById(R.id.tab4_raw_img);
				convertView.setTag(holder);
			}
			if (((GetMsgBean) element).getName().length() > 12) {
				holder.title.setText(((GetMsgBean) element).getName().substring(0, 12)+"...");
			}else{
				holder.title.setText(((GetMsgBean) element).getName());
			}
			holder.date.setText(Helper.timestampToDate(((GetMsgBean) element).getTime(), "yyyy/MM/dd"));
			if (((GetMsgBean) element).getIsNew()) {
				holder.img.setImageResource(R.drawable.icon01);
				holder.title.setTextColor(0xff575757);
				holder.date.setTextColor(0xff575757);
			}else{
				holder.img.setImageResource(R.drawable.icon02);
				holder.title.setTextColor(0xffc6c6c6);
				holder.date.setTextColor(0xffc6c6c6);
			}

			return convertView;
		}

		private class ViewHolder {
			TextView title,date;
			ImageView img;
		}
	}

}
